'''
draw circle 
'''
from  tkinter import *
import math

class CanvasAxisHelper:
    OX = 400
    OY = 400
    MAX_X = 800 
    MAX_Y = 800 
    SCALE_X = 80
    SCALE_Y = 80

    X_Fix=40
    Y_Fix=40

    def draw_point (canvas,x,y,r =1, c="black"):
        canvas.create_oval(x-r,y+r,x+r,y+r,fill=c,outline=c)
    
    @classmethod
    def draw_axes(cls,canvas,OX,OY,width,height):
        #use canvas axis
        # (0,500) -> (800,500)
        # draw x axis
        point1 = (0+cls.X_Fix,OY)
        point2 = (width-cls.X_Fix,OY)
        canvas.create_line(point1,point2)
   
        cls.draw_text_fix(canvas,point1,"({},{})".format(point1[0],point1[1]),False)
        cls.draw_text_fix(canvas,point2,"({},{})".format(point2[0],point2[1]),False)
        # (400,0) -> (400,600)
        # draw y axis
   
        point1= (OX,0+cls.Y_Fix)
        point2 = (OX,height-cls.Y_Fix)
        canvas.create_line(point1,point2)
        cls.draw_text_fix(canvas,point1,"({},{})".format(point1[0],point1[1]),False)
        cls.draw_text_fix(canvas, point2,"({},{})".format(point2[0],point2[1]),False)

    @classmethod
    def plot(cls,canvas,x,y):
        # axis convert 
        cls.draw_point(canvas,cls.SCALE_X*x+ cls.OX,cls.OY-cls.SCALE_Y*y)
    
    """_summary_
    need_fix：是否使用坐标轴转换
    """
    @classmethod
    def draw_text_fix(cls,canvas,point,text,need_fix=True):
    
        x,y=point
        fix_x=x
        fix_y=y
        fill_color="black"
        if(need_fix):
            fill_color="red"   
            fix_x= cls.SCALE_X*x+ cls.OX
            fix_y=cls.OY-cls.SCALE_Y*y
        
        canvas.create_text(fix_x,fix_y,text=text,fill=fill_color)

        
    @classmethod
    def draw_init(cls,canvas):
        cls.draw_axes(canvas,cls.OX,cls.OY,cls.MAX_X,cls.MAX_Y)
        cls.draw_text_fix(canvas,(0,0),"(0,0)",TRUE)

